﻿package mortal.game.view.rebate.openServerSevenDay.panel
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;
    import mortal.game.view.rebate.openServerSevenDay.item.*;
    import mortal.mvc.core.*;

    public class OpenServerDayPanel extends GSprite
    {
        protected var _top:OpenServerSevenDayTop;
        public var _bottom:OpenServerSevenDayBottom;
        public var _bottom2:OpenServerSevenDayBottom2;
        protected var _dayTab:OpenServerSevenDayDayTabPanel;
        public var isUILoadFlag:Boolean = false;
        private var _tabSelectDay:int;

        public function OpenServerDayPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.openServerSevenDay, this.onResLoadSen);
            return;
        }// end function

        private function onResLoadSen() : void
        {
            if (this.isDisposed)
            {
                return;
            }
            this.isUILoadFlag = true;
            this._top = UIFactory.getUICompoment(OpenServerSevenDayTop, 0, 0, this);
            this._bottom = UIFactory.getUICompoment(OpenServerSevenDayBottom, 0, 285, this);
            this._bottom2 = UIFactory.getUICompoment(OpenServerSevenDayBottom2, 0, 285, this);
            this._bottom2.visible = false;
            this._dayTab = UIFactory.getUICompoment(OpenServerSevenDayDayTabPanel, -2, 243, this);
            this._dayTab.configEventListener(EventName.RebateTabSelect, this.onSelectHd);
            this.initTab();
            this.openToday();
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateOpenServerSevenDayReq, tabIndex));
            return;
        }// end function

        private function initTab() : void
        {
            this._dayTab.initTabs();
            return;
        }// end function

        private function openToday() : void
        {
            var _loc_1:* = new DataEvent("");
            var _loc_2:* = RebateUtil.getTargetType();
            var _loc_3:int = 2;
            if (ETargetType._ETargetTypeUNKNOWN == _loc_2)
            {
                _loc_1.data = 0;
            }
            else
            {
                _loc_1.data = _loc_3;
            }
            this.onSelectHd(_loc_1);
            this._dayTab.selectIndex(_loc_3);
            return;
        }// end function

        private function onSelectHd(event:DataEvent) : void
        {
            var _loc_2:int = 0;
            if (event == null)
            {
                _loc_2 = 0;
            }
            else
            {
                _loc_2 = event.data as int;
            }
            this._top.updateTimeByIndex(_loc_2);
            var _loc_3:* = this._dayTab.getDayNumByIndex(_loc_2);
            this.updateBottomByDay(_loc_3);
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateOpenServerSevenDayReq, _loc_2));
            return;
        }// end function

        public function setRangeData(param1:Array, param2:int) : void
        {
            if (param1 == null || param1.length == 0)
            {
                return;
            }
            var _loc_3:* = param1[0] as SToplist;
            this._bottom.updateRole(_loc_3, param2);
            return;
        }// end function

        public function updateCanGet() : void
        {
            this.updateGetBtn();
            this.updateRewards();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this.isUILoadFlag == false)
            {
                return;
            }
            this.isUILoadFlag = false;
            this._top = null;
            this._bottom = null;
            this._bottom2 = null;
            this._dayTab = null;
            LoaderHelp.removeResEvent(ResFileConst.openServerSevenDay, this.onResLoadSen);
            return;
        }// end function

        public function updateBottomByDay(param1:int) : void
        {
            this._tabSelectDay = param1;
            if (OpenServerSevenDayUtil.isOpenRank)
            {
                this._bottom.visible = true;
                this._bottom.updateBottomByDayNum(this._tabSelectDay);
                return;
            }
            if (this._tabSelectDay == 99 || this._tabSelectDay == 100)
            {
                this._bottom.visible = true;
                this._bottom2.visible = !this._bottom.visible;
                this._bottom.updateBottomByDayNum(this._tabSelectDay);
            }
            else
            {
                this._bottom.visible = false;
                this._bottom2.visible = !this._bottom.visible;
                this._bottom2.updateBottomByDayNum2(this._tabSelectDay);
            }
            return;
        }// end function

        public function updateGetBtn() : void
        {
            if (OpenServerSevenDayUtil.isOpenRank)
            {
                this._bottom.visible = true;
                this._bottom.updateGetBtn();
                return;
            }
            if (this._tabSelectDay == 99 || this._tabSelectDay == 100)
            {
                this._bottom.visible = true;
                this._bottom2.visible = !this._bottom.visible;
                this._bottom.updateGetBtn();
            }
            else
            {
                this._bottom.visible = false;
                this._bottom2.visible = !this._bottom.visible;
                this._bottom2.updateGetBtn2();
            }
            return;
        }// end function

        public function updateRewards() : void
        {
            if (OpenServerSevenDayUtil.isOpenRank)
            {
                this._bottom.visible = true;
                this._bottom.updateRewards();
                return;
            }
            if (this._tabSelectDay == 99 || this._tabSelectDay == 100)
            {
                this._bottom.visible = true;
                this._bottom2.visible = !this._bottom.visible;
                this._bottom.updateRewards();
            }
            else
            {
                this._bottom.visible = false;
                this._bottom2.visible = !this._bottom.visible;
                this._bottom2.updateRewards2();
            }
            return;
        }// end function

    }
}
